package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.ProductReview;
import com.qf.entity.ProductReviewDTO;
import com.qf.entity.ProductReviewVO;
import com.qf.service.ProductReviewService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * --- 万物归集  不随你我 ---
 * <p>
 * 快捷短语
 * main ==  public static void main(String[] args);
 * sout ==  System.out.println();
 *
 * @author shuhan
 * @date 2025/5/4
 * @desc
 */
@RestController
@RequestMapping("/product/productReview")
public class ProductReviewController {
    @Autowired
    private ProductReviewService productReviewService;

    @PostMapping("/findAllReviews")
    public R findAllReviews(@RequestBody ProductReviewDTO productReview) {
        PageHelper.startPage(productReview.getPageNum(), productReview.getPageSize());
        List<ProductReview> productReviews = productReviewService.findAllReviews();
        PageInfo<ProductReview> pageInfo = new PageInfo<>(productReviews);
        return R.ok(pageInfo);
    }
    @GetMapping("/deleteReviewsById")
    public R deleteReviewById(Integer id) {
        productReviewService.deleteReviewById(id);
        return R.ok();
    }

    @PostMapping("/saveReviews")
    public R saveReviews(@RequestBody ProductReviewVO productReviewVO) {
        productReviewService.saveReviews(productReviewVO);
        return R.ok();
    }
    @PostMapping("/updateReviews")
    public R updateReviews(@RequestBody ProductReviewVO productReviewVO) {
        productReviewService.updateReviews(productReviewVO);
        return R.ok();
    }
}
